/********************
Figure 2. Effect of EITC in Uber Areas on Business Income and Total Income Distribution of Single, Less-educated Households
********************/

use "data\hslesshousehold_ubereitc2005_2019", clear

ihstrans incbus002020

forval i = 5(5)45 {
		local j = `i'-5
		gen faminc_`i' = ftotinc2020>=(`j'*1000) & ftotinc2020<(`i'*1000)
		replace faminc_`i' = . if ftotinc2020 == .
		
		gen selfinc_`i' = incbus002020>=(`j'*1000) & incbus002020<(`i'*1000)
		replace selfinc_`i' = . if incbus002020 == .
}
gen faminc_0 = ftotinc2020<0
gen faminc_50 = ftotinc2020>=45000 & ftotinc2020<50000

gen selfinc_0 = incbus002020<0
gen selfinc_50 = incbus002020>=45000 & incbus002020<50000

reghdfe faminc_5 max_total_credit2020 max_total_credit2020_uber uber_exposed [pw = hhwt] if head_hsorless == 1 & hh_married == 0, absorb(st_yr cbsa_id num_ekids) vce(cluster stfips) 

keep if e(sample) == 1

gen cutoff = _n*5-5 if _n<=11
gen fbeta = .
gen fse = .
gen fm_lb = .
gen fm_ub = .

gen sbeta = .
gen sse = .
gen sm_lb = .
gen sm_ub = .

foreach v in 0 5 10 15 20 25 30 35 40 45 50 {
		reghdfe faminc_`v' max_total_credit2020 max_total_credit2020_uber uber_exposed [pw = hhwt] if head_hsorless == 1 & hh_married == 0, absorb(st_yr cbsa_id num_ekids) vce(cluster stfips) 
		replace fbeta = _b[max_total_credit2020_uber] if cutoff == `v'
		replace fse = _se[max_total_credit2020_uber]  if cutoff == `v'
		scalar edf_r = e(df_r)

		replace fm_lb = fbeta-fse*invttail(`=scalar(edf_r)',.025) if cutoff == `v'
		replace fm_ub = fbeta+fse*invttail(`=scalar(edf_r)',.025) if cutoff == `v'
		
		reghdfe selfinc_`v' max_total_credit2020 max_total_credit2020_uber uber_exposed [pw = hhwt] if head_hsorless == 1 & hh_married == 0, absorb(st_yr cbsa_id num_ekids) vce(cluster stfips) 
		replace sbeta = _b[max_total_credit2020_uber] if cutoff == `v'
		replace sse = _se[max_total_credit2020_uber]  if cutoff == `v'
		scalar edf_r = e(df_r)

		replace sm_lb = sbeta-sse*invttail(`=scalar(edf_r)',.025) if cutoff == `v'
		replace sm_ub = sbeta+sse*invttail(`=scalar(edf_r)',.025) if cutoff == `v'
}

	
//I want the cutoff to be at the lower end of the bar and in thousands of dollars
gen cutoff_mod = cutoff*1000-2500
lab def cutoffs -2500 "Under $0" 2500 "$0-5K" 7500 "$5-10K" 12500 "$10-15K" 17500 "$15-20K" 22500 "$20-25K" 27500 "$25-30K" 32500 "$30-35K" 37500 "$35-40K" 42500 "$40-45K" 47500 "$45-50K" , replace
lab val cutoff_mod cutoffs

//I also want to plot the EITC schedule
gen eitc_cutoff0 = .
replace eitc_cutoff0 = 0 if _n == 1
replace eitc_cutoff0 = 5980 if _n == 2
replace eitc_cutoff0 = 7480 if _n == 3
replace eitc_cutoff0 = 13460 if _n == 4

gen eitc_amnt0 = .
replace eitc_amnt0 = 0 if _n == 1
replace eitc_amnt0 = 457 if _n == 2
replace eitc_amnt0 = 457 if _n == 3
replace eitc_amnt0 = 0 if _n == 4

gen eitc_cutoff1 = .
replace eitc_cutoff1 = 0 if _n == 1
replace eitc_cutoff1 = 8970 if _n == 2
replace eitc_cutoff1 = 16420 if _n == 3
replace eitc_cutoff1 = 35463 if _n == 4

gen eitc_amnt1 = .
replace eitc_amnt1 = 0 if _n == 1
replace eitc_amnt1 = 3043 if _n == 2
replace eitc_amnt1 = 3043 if _n == 3
replace eitc_amnt1 = 0 if _n == 4


gen eitc_cutoff2 = .
replace eitc_cutoff2 = 0 if _n == 1
replace eitc_cutoff2 = 12590 if _n == 2
replace eitc_cutoff2 = 16450 if _n == 3
replace eitc_cutoff2 = 40363 if _n == 4

gen eitc_amnt2 = .
replace eitc_amnt2 = 0 if _n == 1
replace eitc_amnt2 = 5036 if _n == 2
replace eitc_amnt2 = 5036 if _n == 3
replace eitc_amnt2 = 0 if _n == 4

gen eitc_cutoff3 = .
replace eitc_cutoff3 = 0 if _n == 1
replace eitc_cutoff3 = 12590 if _n == 2
replace eitc_cutoff3 = 16450 if _n == 3
replace eitc_cutoff3 = 43352 if _n == 4

gen eitc_amnt3 = .
replace eitc_amnt3 = 0 if _n == 1
replace eitc_amnt3 = 5666 if _n == 2
replace eitc_amnt3 = 5666 if _n == 3
replace eitc_amnt3 = 0 if _n == 4

lab val eitc_cutoff2 cutoffs
lab val eitc_cutoff3 cutoffs

twoway (bar fbeta cutoff_mod, barwidth(5000) lcolor(black) fcolor(none) yaxis(1)) ///
	(rcap fm_ub fm_lb cutoff_mod, lcolor(black) lwidth(vthin) yaxis(1)) ///
	(line eitc_amnt3 eitc_cutoff3, lwidth(thin) lpattern(__) lcolor(navy*.6) yaxis(2) ///
	text(.004 36000  "3+ Eligible Children", size(vsmall))) ///
	(pcarrowi .0035 36000 .0021 32500 , color(black)) ///
	(line eitc_amnt2 eitc_cutoff2, lwidth(thin) lpattern(_-_) lcolor(maroon*.6) yaxis(2) ///
	text(.002 42000  "2 Eligible Children", size(vsmall))) ///
	(pcarrowi .0015 42000 .0009 37000 , color(black)) ///
	(line eitc_amnt1 eitc_cutoff1, lwidth(thin) lpattern(--) lcolor(maroon*.6) yaxis(2) ///
	text(.002 300  "1 Eligible Children", size(vsmall))) ///
	(pcarrowi .0017 300 .0013 4050 , color(black)) ///
	(line eitc_amnt0 eitc_cutoff0, lwidth(thin) lpattern(--) lcolor(navy*.6) yaxis(2) ///
	text(.001 -500  "0 Eligible Children", size(vsmall))) ///
	(pcarrowi .0008 -500 .0002 1400 , color(black)) ///
	, legend(off /*order(1 "") rows(1)*/) graphregion(color(white)) ///
	xlabel(-2500(5000)47500, valuelabels labsize(*.7)) xtitle("") ytitle(Percentage Points, axis(1)) ///
	yscale(range(-5450 6400) axis(2)) ylabel(0(2000)6000, axis(2)) ylabel(-.005(.001).006, axis(1) labsize(*.7)) ytitle("EITC Amount ($)", axis(2)) subtitle("Total Family Income ($2020)")
	
	
graph export "output\impacteitcuber_ftotincdist_hssingle.pdf", replace

twoway (bar sbeta cutoff_mod, barwidth(5000) lcolor(black) fcolor(none) yaxis(1)) ///
	(rcap sm_ub sm_lb cutoff_mod, lcolor(black) lwidth(vthin) yaxis(1)) ///
	(line eitc_amnt3 eitc_cutoff3, lwidth(thin) lpattern(__) lcolor(navy*.6) yaxis(2) ///
	text(.0018 36000  "3+ Eligible Children", size(vsmall))) ///
	(pcarrowi .0017 36000 .001 32500 , color(black)) ///
	(line eitc_amnt2 eitc_cutoff2, lwidth(thin) lpattern(_-_) lcolor(maroon*.6) yaxis(2) ///
	text(.001 42000  "2 Eligible Children", size(vsmall))) ///
	(pcarrowi .0008 42000 .00045 36500 , color(black)) ///
	(line eitc_amnt1 eitc_cutoff1, lwidth(thin) lpattern(--) lcolor(maroon*.6) yaxis(2) ///
	text(.001 300  "1 Eligible Children", size(vsmall))) ///
	(pcarrowi .0009 300 .0006 4500 , color(black)) ///
	(line eitc_amnt0 eitc_cutoff0, lwidth(thin) lpattern(--) lcolor(navy*.6) yaxis(2) ///
	text(.0005 -500  "0 Eligible Children", size(vsmall))) ///
	(pcarrowi .0004 -500 .00002 1400 , color(black)) ///
	, legend(off /*order(1 "") rows(1)*/) graphregion(color(white)) ///
	xlabel(-2500(5000)47500, valuelabels labsize(*.7)) xtitle("") ytitle(Percentage Points, axis(1)) ///
	yscale(range(-6500 6400) axis(2)) ylabel(0(2000)6000, axis(2)) ylabel(-.0025(.0005).0025, axis(1) labsize(*.7)) ytitle("EITC Amount ($)", axis(2)) subtitle("Total Self Employment Income ($2020)")

graph export "output\impacteitcuber_selfincdist_hssingle.pdf", replace
